package com.fenghongzhang.a1902;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main2Activity extends AppCompatActivity {


    @BindView(R.id.tab)
    CommonTabLayout tab;
    @BindView(R.id.vp)
    ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ButterKnife.bind(this);

        String[] strings = {"标题","内容"};
        List<Fragment> list = new ArrayList<>();
//        fragmentList = new ArrayList<>();

        list.add(new OneFragment());
        list.add(new TwoFragment());


        vp.setAdapter(new MyAdapter(getSupportFragmentManager(),list));
//        tab.setViewPager(vp,strings);
//        fragmentList.add(new MainFragment());
        ArrayList<CustomTabEntity> mTabEntitys = new ArrayList<>();
        mTabEntitys.add(new MainTabAdapter("首页",R.mipmap.ic_launcher,R.mipmap.ic_launcher_round));
        mTabEntitys.add(new MainTabAdapter("haha",R.mipmap.ic_launcher,R.mipmap.ic_launcher_round));
        tab.setTabData(mTabEntitys);

        vp.setCurrentItem(0);
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tab.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        tab.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                vp.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }


}
